﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class admin_cms_Qc_News : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["timeout"] == null)
            {
                Response.Redirect("login.aspx");
            }
            else
            {
                Griv_Banner_all();
            }

        }

        // load dữ liệu lên griv

    }
    protected void bt_them_advertis_banner(object sender, EventArgs e)
    {
        string title = txttile.Text;
        string body = fcknew.Value.ToString();
        bool isimage = false;
        bool isflash = false;
        string createby = " ";
        if (Session["timeout"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            createby = Session["timeout"].ToString();
            DataAccess.ExeNonSQL("Insert into dev_recruitment(title,body,createby) values(N'" + title + "',N'" + body + "','" + createby + "')");
            Griv_Banner_all();

        }






    }

    protected void Griv_Banner_all()
    {
        DataTable dt_grive_banner = new DataTable();
        dt_grive_banner = DataAccess.ExeSQLToDataTable("select * from dev_recruitment");
        Griv_Banner.DataSource = dt_grive_banner;
        Griv_Banner.DataBind();
    }
    protected void bt_sua_advertis_banner(object sender, EventArgs e)
    {
        string title = txttile.Text;
        string body = fcknew.Value.ToString();
        bool isimage = false;
        bool isflash = false;
        string updateby = " ";
        string id = Session["id_banner"].ToString();
        if (Session["timeout"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            updateby = Session["timeout"].ToString();
            DataAccess.ExeNonSQL("update dev_recruitment set title=N'" + title + "',body=N'" + body + "' where id='" + id + "'");
            Griv_Banner_all();

        }


    }


    /// <summary>
    /// load theo đệ quy vào dropdownlist
    /// </summary>
    /// <param name="dtDrop"></param>
    /// <param name="dtnews"></param>
    /// <param name="IdParent"></param>
    /// <param name="level"></param>
    /// <returns></returns>
    protected DataTable load_drop_process(DataTable dtDrop, DataTable dtnews, string IdParent, int level)
    {
        int countall = dtnews.Rows.Count;

        for (int i = 0; i < countall; i++)
        {
            if (dtnews.Rows[i][1].ToString() == IdParent)
            {
                string idMenu = dtnews.Rows[i][0].ToString();

                //Khai 1 bao doi tuong DataRow
                DataRow drItems;
                drItems = dtDrop.NewRow();

                drItems["name_menu"] = levelMenu(level) + dtnews.Rows[i][2].ToString();
                drItems["link_web"] = dtnews.Rows[i][3].ToString();
                dtDrop.Rows.Add(drItems);

                load_drop_process(dtDrop, dtnews, idMenu, level + 1);
            }
        }
        return dtDrop;
    }

    protected string levelMenu(int value)
    {
        string str = "";
        for (int i = 0; i < value; i++)
        {
            str += "*";
        }
        return str;
    }


    public static string test_browrs_menu(bool value)
    {
        string htmlCode = "menu_browrs_off";
        if (value == true)
        {
            htmlCode = "menu_browrs_on";
        }
        return htmlCode;
    }

    public static string test_cant_delete(bool value)
    {
        string htmlCode = "<img alt='' src='style/img/close_16.png' title='Click to Delete' />";
        if (value == true)
        {
            htmlCode = "<img alt='' src='style/img/close_off_16.png' title='Can not Delete' />";
        }

        return htmlCode;
    }

    public static bool bool_inverse(bool value)
    {
        bool set = false;
        if (value == false)
        {
            set = true;
        }
        return set;
    }
    protected void news_grAll_click(object sender, CommandEventArgs e)
    {
        string Argvalue = e.CommandArgument.ToString();
        char[] ch = new char[] { '|' };

        string[] s = ITNLip.SplitString(Argvalue, ch);
        string id = s[0];
        string action = s[1];
        string value = s[2];

        switch (action)
        {

            
            case "delete":

                DataAccess.ExeNonSQL("delete dev_recruitment where id='" + id + "'");
                break;
            case "edit":
                DataTable dt_admin_advertis = new DataTable();
                Button1.Enabled = false;
                Button2.Enabled = true;
                dt_admin_advertis = DataAccess.ExeSQLToDataTable("select * from dev_recruitment where id='" + id + "'");
                if (dt_admin_advertis.Rows.Count > 0)
                {
                    txttile.Text = dt_admin_advertis.Rows[0][1].ToString();
                    fcknew.Value = dt_admin_advertis.Rows[0][3].ToString();
                    Session.Add("id_banner", id);
                }
                break;
        }
        Griv_Banner_all();
    }
    
}
